<template>
    <topHeader :title="'登录'" :color="'#4a92ff'" :background="'#fff'" :back="true"></topHeader>
    <view class="loginView">
        <h1 class="title">订单售后</h1>
        <input class="input" placeholder="请输入手机号" v-model="phone" />
        <input class="input" placeholder="请输入密码" type="password" v-model="password" />
        <button class="login_button" @click="loginFn">{{ props.type == 1 ? '切换账号' : '登录小程序' }}</button>
        <!--  <button open-type="getPhoneNumber" class="login_button" @getphonenumber="loginGET">登录小程序</button> -->
        <view class="once" @click="goBackFn" v-if="props.type == 1">暂不切换</view>
        <navigator open-type="exit" class="once" target="miniProgram" v-else>暂不登录</navigator>
        <view class="deal">
            <label class="radio" @click="radioFn">
                <radio :checked="dealdata" class="info" />
                <text>若你手机号未注册,登陆时将自动注册,且代表您同意</text>
            </label>
            <text class="deal-t">
                《用户服务协议》
                <text>和</text>
                《隐私权政策》
            </text>
        </view>
    </view>
    <!--    <view class="userinfo" v-if="isUserInfo">
        <view class="user_box">
            <view class="top">获取信息</view>
            <view class="content">是否允许获取您的微信昵称</view>
            <view class="bot">
                <view class="" @click="isUserInfo = false">不获取</view>
                <button class="open_get" open-type="getUserInfo" @getuserinfo="onGetUserInfo">获取</button>
            </view>
        </view>
    </view> -->
</template>

<script setup>
import topHeader from '@/pages/components/topHeader.vue';
import { ref, nextTick } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { loginUserApi } from '@/pages/request/loginApi.js';
const dealdata = ref(false); //单选checked
const isUserInfo = ref(false); //单选checked
const ass_token = ref('');
const props = defineProps(['type']);
// 单选按钮
const radioFn = () => {
    dealdata.value = !dealdata.value;
};
const phone = ref();
const password = ref();
async function loginFn() {
    const res = await loginUserApi({ username: phone.value, password: password.value });
    if (res.code == 0) {
        uni.showToast({
            title: res.msg,
            icon: 'none'
        });
    }
    uni.setStorageSync('newToken', res.data.userinfo.token);
    uni.redirectTo({
        url: '/pages/home/index'
    });
}
function goBackFn() {
    uni.redirectTo({
        url: '/pages/home/index'
    });
}
//

onShow(() => {});
</script>

<style lang="scss" scoped>
.userinfo {
    width: 1000%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.2);
    position: absolute;
    top: 0;
    z-index: 9999;
    .user_box {
        width: 85vw;
        height: 280rpx;
        background-color: #fff;
        margin-top: 40vh;
        margin-left: 8vw;
        border-radius: 10rpx;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        .top {
            font-size: 36rpx;
        }
        .content {
            font-size: 28rpx;
        }
        .bot {
            width: 80%;
            display: flex;
            justify-content: space-evenly;
            align-items: center;
            .open_get {
                margin: 0 !important;
            }
        }
    }
}
.loginView {
    // width: 100%;
    padding: 0 5vw;
    text-align: center;
    .input {
        width: 700rpx;
        height: 80rpx;
        margin: 20rpx auto;
        text-align: left;
    }
    .title {
        font-size: $uni-img-size-base;
        margin-bottom: 10vw;
        margin-top: 30vw;
        font-weight: 700;
    }
    .title-tow {
        font-size: $uni-font-size-lg;
        margin-bottom: 10vw;
    }
    .login_button {
        width: 90vw;
        height: 12vw;
        font-size: $uni-img-size-sm;
        margin-bottom: 3vw;
        padding: 0;
        margin: 0;
        border-radius: 20vw;
        line-height: 12vw;
        color: #fff;
        margin-bottom: 2vw;
        background-color: #2f78ff;
    }
    .deal {
        width: 90vw;
        font-size: $uni-spacing-row-base;
        color: $uni-text-color-placeholder;
        text-align: center;
        .radio {
            radio {
                transform: scale(0.6);
            }
        }
        .deal-t {
            color: $uni-color-primary;
            text {
                color: $uni-text-color-placeholder;
            }
        }
    }
    .once {
        width: 90vw;
        height: 12vw;
        font-size: $uni-img-size-sm;
        margin-bottom: 3vw;
        padding: 0;
        margin: 0;
        line-height: 12vw;
        color: #999;
        margin-bottom: 2vw;
    }
}
</style>
